package com.ulife.permission.manager.impl;

import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Autowired;

import com.ulife.common.Result;
import com.ulife.common.exception.ManagerException;
import com.ulife.permission.dao.FunctionDao;
import com.ulife.permission.dao.dataobject.FunctionDO;
import com.ulife.permission.manager.FunctionManager;

public class FunctionManagerImpl implements FunctionManager {

	@Autowired
	private FunctionDao functionDao;

	public Result<FunctionDO> getFunctionByFunctionId(String functionId) throws ManagerException {
		Result<FunctionDO> result = new Result<FunctionDO>();
		try {
			FunctionDO function = functionDao.getFunctionByFunctionId(functionId);
			if (function != null) {
				result.setSuccess(true);
				result.setModule(function);
			}
			return result;
		} catch (SQLException e) {
			throw new ManagerException(e);
		}
	}

	public Result<Integer> updateFunction(FunctionDO functionDO) throws ManagerException {
		Result<Integer> result = new Result<Integer>();
		try {
			int i = functionDao.updateFunction(functionDO);
			if (i > 0) {
				result.setSuccess(true);
			}
			return result;
		} catch (SQLException e) {
			throw new ManagerException(e);
		}
	}

	public Result<Integer> addFunction(FunctionDO functionDO) throws ManagerException {
		Result<Integer> result = new Result<Integer>();
		try {
			int id = functionDao.addFunction(functionDO);
			if (id > 0) {
				result.setSuccess(true);
			}
			return result;
		} catch (SQLException e) {
			throw new ManagerException(e);
		}
	}

}
